package com.fulin.leetcode;

import java.util.Date;

/**
 * @Description 将一个字符串进行Z字型变化
 *  算法：核心逻辑就是将每行的字符单独存在一个容器中。遍历原字符串决定当前字符放入那个容器，而遍历的关键就是有一个从0到 n再从n到0的循环往复的过程
 * @Author fulin16
 * @Date 2020/10/21 17:07
 **/
public class Num6 {
    public String convert(String s, int numRows) {
        if(numRows < 2){
            return s;
        }
        StringBuilder[] rows = new StringBuilder[numRows];

        for(int i = 0 ;i < numRows ; i ++){
            rows[i] = new StringBuilder();
        }

        int index = 0,flag = -1;
        for(int i = 0; i < s.length();i++){
            rows[index].append(s.charAt(i));
            if(index == 0 || index == numRows -1 ){
                flag = - flag;
            }
            index += flag;
        }

        StringBuilder sb = new StringBuilder();
        for(int i = 0; i< numRows;i++){
            sb.append(rows[i].toString());
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(System.currentTimeMillis());
        System.out.println(new Date().getTime());
    }
}
